<template>
  <view class="scan-container">
    <!-- 扫码区域 -->
    <view class="scan-box">
      <!-- <image class="scan-icon" src="/static/scan-icon.png" mode="aspectFit"></image> -->
      <view class="scan-text">将取件码放入框内扫描</view>
    </view>

    <!-- 扫码按钮 -->
    <button class="scan-btn" @click="startScan">
      <text>开始扫码</text>
      <uni-icons type="scan" size="20" color="#fff"></uni-icons>
    </button>

    <!-- 提示文字 -->
    <view class="tip-text">扫码取件码完成订单</view>

    <!-- 扫码结果 -->
    <!-- <view class="result-box" v-if="scanResult">
      <view class="result-title">扫码结果：</view>
      <view class="result-content">{{scanResult}}</view>
    </view> -->
  </view>
</template>

<script>
export default {
  data() {
    return {
      scanResult: "",
    };
  },
  methods: {
    // 开始扫码
    startScan() {
      uni.scanCode({
        success: (res) => {
          this.scanResult = res.result;
          this.processScanResult(this.scanResult);
        },
        fail: (err) => {
          uni.showToast({
            title: "扫码失败，请重试",
            icon: "none",
          });
        },
      });
    },

    // 处理扫码结果
    processScanResult(url) {
      // 跳转到指定页面
      uni.navigateTo({
        url: url, // 直接使用扫码获取的URL
      });
    },
    // ... existing code ...
  },
};
</script>

<style lang="scss">
.scan-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40rpx;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);

  .scan-box {
    width: 80%;
    height: 300rpx;
    margin: 60rpx 0;
    background: #fff;
    border-radius: 20rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);

    .scan-icon {
      width: 120rpx;
      height: 120rpx;
    }

    .scan-text {
      margin-top: 20rpx;
      color: #666;
      font-size: 28rpx;
    }
  }

  .scan-btn {
    width: 80%;
    height: 80rpx;
    margin-top: 40rpx;
    background: linear-gradient(135deg, #007aff 0%, #005bb5 100%);
    color: #fff;
    border-radius: 40rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4rpx 12rpx rgba(0, 122, 255, 0.3);
    border: none;

    text {
      margin-right: 10rpx;
      font-size: 32rpx;
    }
  }

  .tip-text {
    margin-top: 30rpx;
    color: #999;
    font-size: 24rpx;
  }

  .result-box {
    width: 80%;
    margin-top: 60rpx;
    padding: 30rpx;
    background: #fff;
    border-radius: 20rpx;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);

    .result-title {
      font-size: 28rpx;
      color: #333;
      font-weight: bold;
      margin-bottom: 20rpx;
    }

    .result-content {
      font-size: 26rpx;
      color: #666;
      word-break: break-all;
    }
  }
}
</style>